<template>
  <div>
    <label v-for="(item, index) in arr" :key="index">
      <input type="checkbox" v-model="sumArr" :value="item" />{{ item }}
    </label>
    <h4>您选中的元素累加值为：{{ allSum }}</h4>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [9, 15, 19, 25, 29, 31, 48, 57, 62, 79, 87],
      sumArr: [], //保存用户所传的数字
    };
  },
  computed: {
    allSum() {
      return this.sumArr.reduce((sum, last) => {
        return (sum += last);
      }, 0);
    },
  },
};
</script>

<style scoped></style>
